package leetcode;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

public class LC24 {
    public static void main(String[] args) {
        LC24 lc24 = new LC24();
        System.out.println(lc24.isPalindrome(ListNode.ln(new int[]{1,0,0})));
        System.out.println(lc24.isPalindrome(ListNode.ln(new int[]{1, 2, 2, 1})));
        System.out.println(lc24.isPalindrome(ListNode.ln(new int[]{1, 2, 1})));
    }

    public boolean isPalindrome(ListNode head) {
        List<Integer> list = new ArrayList<>();
        while(head != null){
            list.add(head.val);
            head = head.next;
        }
        for (int i = 0,j = list.size() - 1; i < j; i++, j--) {
            if (!Objects.equals(list.get(i), list.get(j))) return false;
        }
        return true;
    }
}
